<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
     <!-- id标识vue作用的范围 -->
    <div id="app">
      <button v-on:click="getTeacherList()">获取讲师列表</button>
      <table>
          <tr v-for="teacher in teacherList">
              <td>{{teacher.name}}</td>
              <td>{{teacher.level}}</td>
          </tr>
      </table>
    </div>
    <script src="vue.min.js"></script>
    <script src="axios.min.js"></script>
    <!-- 引入js -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script>
        //创建一个vue对象
        new Vue({
            //绑定vue作用的范围
            el: '#app',//element 我要管理页面的那个节点
            data:{
                teacherList:[]
            },//页面一加载调用的方法
            created () {
                this.getTeacherList()
            },
            methods: {
                //初始化axios的基本环境
                initRequest(){
                     //axios.create()方法的返回值是一个函数引用
                    return axios.create({
                        baseURL: 'http://localhost:8110/'
                    })
                },
                teacherListApi(){
                    let request=this.initRequest()
                   //console.log(typeof request)
                   return request({
                       url: 'admin/edu/teacher/list',
                       mathod: 'get'
                   })
                },
                getTeacherList(){
                    
                  this.teacherListApi().then(response=>{
                        //reseponse是标准的http响应
                        console.log(response)
                        //数据绑定到data数据模型
                        this.teacherList=response.data.data.items
                        console.log(this.teacherList)
                    }).catch(error=>{
                        console.log("error",error)
                    })

                    //axious 执行ajax访问
                    // then:请求成功的回调函数
                    //promise
                    // axios.get("admin/edu/teacher/list").then(response=>{
                    //     //reseponse是标准的http响应
                    //     console.log(response)
                    //     //数据绑定到data数据模型
                    //     this.teacherList=response.data.data.items
                    //     console.log(this.teacherList)
                    // }).catch(error=>{
                    //     console.log("error",error)
                    // })

                }
            }
        })
    </script>
</body>
</html>